﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CarolLib;
using MiniCMS.Business;
using MiniCMS.Model;

namespace MiniCMS
{
    public class AuthUserContext
    {
        public static AuthUserContext Instance = new AuthUserContext();

        public SystemUser User;

        private AuthUserContext()
        {
        }

        public bool Login(string account, string pwd)
        {
            try
            {
                var result = OleDbDataProvider.Login(account, pwd);
                if (result == null)
                    return false;

                Instance = new AuthUserContext();
                Instance.User = result;

                return true;
            }
            catch (System.Net.WebException wex)
            {
                MessageBox.Show("网络错误：" + wex.Message);
                return false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("未知错误：" + ex.Message);
                return false;
            }
        }

        public static string Encrypt(string text)
        {
            return CarolLib.EncryptHelper.EncryptString(text, "asdkfjoiu*(^");
        }

        public static string Dencrypt(string text)
        {
            return CarolLib.EncryptHelper.DecryptString(text, "asdkfjoiu*(^");
        }
    }
}
